home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: delta / whiteline CD Series - delta.iso / tex / style / misc / epsfig.sty < prev    next >
Text File  |  1995-11-25  |  28KB  |  866 lines

  1. \def\fileversion{v1.1}
  2. \def\filedate{4 Dec 91}
  3. \immediate\write16{Document style option `epsfig', \fileversion\space
  4. <\filedate> (edited by SPQR)}
  5. %%%--------------------------------------------------------------------
  6. %%% psfig merged with EPSF =epsfig Release 1 
  7. %%%
  8. %%% code rearranged by Sebastian Rahtz from work by
  9. %%% Trevor Darrell; Tom Rokicki; Daniel Smith; H. Payne, Robert Russell
  10. %%%
  11. %%% This is a version of Darrell's `psfig' macros which are designed  only
  12. %%% to be used with Rokicki's dvips program and the `epsf' macros (these
  13. %%% are automaticaly included by the style file). I did this because the
  14. %%% \special commands used by `epsf' appear to be more robust and 
  15. %%% portable than the raw \specials used by `psfig', but I preferred the
  16. %%% psfig interface, and wanted to use some of its features which epsf
  17. %%% did not offer (specifically, clipping to the BoundingBox). This system
  18. %%% preserves the psfig interface, but mainly uses epsf macros to carry out
  19. %%% the job. The user interface is identical to \psfig, but you just use  
  20. %%% \epsfig instead. Clipping and rotation uses the original psfig macros, 
  21. %%% as do specific settings of the Bounding Box in the call to the macro. 
  22. %%% I could not work out how to do rotation or clipping with the epsf macros.
  23. %%%
  24. %%% The same applies to `rheight' and `rwidth'
  25. %%%
  26. %%% One behaviour which may confuse people is that setting width= and 
  27. %%% height will *not* force a change in the aspect ratio. If you need
  28. %%% this behaviour, use the \psfig macro instead of \epsfig. Rokicki's macros
  29. %%% do not provide a way of doing the aspect ration stuff.
  30. %%%  
  31. %%% If you *really* want old psfig behaviour regardless, use \psfig. It is
  32. %%% still there. Some of the features have gone, however. \figurepath
  33. %%% seemed redundant, since it could be controlled by the TEXINPUTS
  34. %%% variable anyway. 
  35. %%%  
  36. %%% As an added feature, if a file cannot be found, a file called `file'.bb
  37. %%% is searched for. This should simply contain a %%BoundingBox line. It is
  38. %%% assumed that if this exists, then `file'.Z exists, and is a Unix
  39. %%% compressed file. The macros then read the BB from `file'.bb, but insert
  40. %%% "zcat `file'.Z" in the  output for dvips to interpret (don't worry, it
  41. %%% knows about this). Saves a lot  of space! Actually, its more
  42. %%% complicated than that; the string passed to dvips for file `foo.ps' is
  43. %%% actually "zcat `texfind foo.ps.Z`", where `texfind' is assumed to be  a
  44. %%% shell script which searches the TEXINPUTS path for `foo.ps.Z'. Such a
  45. %%% script comes with dvips. Just alias it to `cat' if you have problems.
  46. %%% If you are *not* on a Unix system and use this, deliberately or by 
  47. %%% mischance, you will have problems!
  48. %%% 
  49. %%% This file can be included in a dumped format, or used as a LaTeX
  50. %%% style file, or used in plain TeX. It does not load itself twice (I hope!)
  51. %%%
  52. %%% Sebastian Rahtz December 1991 spqr@uk.ac.soton.ecs
  53. %--------------------------------------------------------------------
  54. %--------------------------------------------------------------------
  55. %%% previous notes. this copy of psfig.tex inherited from version 1.7
  56. %--------------------------------------------------------------------
  57. %%% All psfig/tex software, documentation, and related files
  58. %%% in this distribution of psfig/tex are 
  59. %%% Copyright 1987, 1988, 1991 Trevor J. Darrell
  60. %
  61. %%% Permission is granted for use and non-profit distribution of psfig/tex 
  62. %%% providing that this notice be clearly maintained. The right to
  63. %%% distribute any portion of psfig/tex for profit or as part of any commercial
  64. %%% product is specifically reserved for the author(s) of that portion.
  65. %%%
  66. %%% Thanks to Greg Hager (GDH) and Ned Batchelder for their contributions
  67. %%% to this project.
  68. %%%--------------------------------------------------------------------------
  69. %%% GDH 7/26/87 -- changed so that it first looks in the local directory,
  70. %%% then in a specified global directory for the ps file.
  71. %%% SPQR 12/91 removed that last change. it follows TEXINPUTS anyway
  72. %%% RPR 6/25/91 -- changed so that it defaults to user-supplied name if
  73. %%% boundingbox info is specified, assuming graphic will be created by
  74. %%% print time.
  75. %%% SPQR 12/91 removed that last change. use LaTeX error message instead
  76. %%% SPQR 12/91 -- `no file found' produces LaTeX error message.
  77. %%%                If you recover from that the file name is set in draft
  78. %%%                mode in place of the file.
  79. %%%
  80. %%% Modified by J. Daniel Smith on 9 October 1990 to accept the
  81. %%% %%BoundingBox: comment with or without a space after the colon.  Stole
  82. %%% file reading code from Tom Rokicki's EPSF.TEX file (see below).
  83. %%% --- SPQR 12.91 removed most of this to use epsf directly
  84. %%%
  85. %%% More modifications by J. Daniel Smith on 29 March 1991 to allow the
  86. %%% the included PostScript figure to be rotated.  The amount of
  87. %%% rotation is specified by the "angle=" parameter of the \epsfig command.
  88. %%%
  89. %%% Modified by Robert Russell on June 25, 1991 to allow users to specify
  90. %%% .ps filenames which don't yet exist, provided they explicitly provide
  91. %%% boundingbox information via the \epsfig command. Note: This will only work
  92. %%% if the "file=" parameter follows all four "bb???=" parameters in the
  93. %%% command. This is due to the order in which psfig interprets these params.
  94. %%% ---- SPQR 12.91 removed all this
  95. %%%
  96. %%% 3 Jul 1991    JDS    check if file already read in once
  97. %%%
  98. %%% Modified by H. Payne on 9 October 1991 to allow rotation through
  99. %%% arbitrary angles, not just angles in the first quadrant.
  100. %--------------------------------------------------------------------------
  101. %%%
  102. %%% from a suggestion by eijkhout@csrd.uiuc.edu to allow
  103. %%% loading as a style file:
  104. \edef\epsfigRestoreAt{\catcode`@=\number\catcode`@\relax}
  105. \catcode`\@=11\relax
  106. % copies of bits of LaTeX we need....
  107. \ifx\@ifundefined\undefined
  108. \long\def\@ifundefined#1#2#3{\expandafter\ifx\csname
  109.   #1\endcsname\relax#2\else#3\fi}
  110. \fi
  111. %
  112. \@ifundefined{typeout}
  113. {\gdef\typeout#1{\immediate\write\sixt@@n{#1}}}
  114. {\relax}
  115. %
  116. %%% check to see if macros already loaded in (maybe some other file says
  117. %%% "\input epsfig") ...
  118. \@ifundefined{epsfig}{}{\typeout{EPSFIG --- already loaded}\endinput}
  119. %
  120. % we try to put a box round space of missing figures. plain TeX
  121. % doesn't have an easy command, so just ignore it
  122. \@ifundefined{fbox}{\def\fbox#1{#1}}{}
  123. %%%
  124. %%% we need Rokicki's EPSF macros anyway, unless they are already loaded
  125. %
  126. \@ifundefined{epsfbox}{\input epsf}{}
  127. %
  128. %% SPQR 12.91 handling of errors using standard LaTeX error 
  129. %% mechanism. In case we are plain TeX we first define the
  130. %% error routines...
  131. \ifx\undefined\@latexerr
  132.     \newlinechar`\^^J
  133.     \def\@spaces{\space\space\space\space}
  134.     \def\@latexerr#1#2{%
  135.     \edef\@tempc{#2}\expandafter\errhelp\expandafter{\@tempc}%
  136.     \typeout{Error. \space see a manual for explanation.^^J
  137.      \space\@spaces\@spaces\@spaces Type \space H <return> \space for
  138.      immediate help.}\errmessage{#1}}
  139. \fi
  140. %------------------------
  141. %% a couple of LaTeX error messages
  142. \def\@whattodo{You tried to include a PostScript figure which 
  143. cannot be found^^JIf you press return to carry on anyway,^^J
  144. The failed name will be printed in place of the figure.^^J
  145. or type X to quit}
  146. \def\@whattodobb{You tried to include a PostScript figure which 
  147. has no^^Jbounding box, and you supplied none.^^J
  148. If you press return to carry on anyway,^^J
  149. The failed name will be printed in place of the figure.^^J
  150. or type X to quit}
  151. %------------------------
  152. %
  153. %------------------------------------------------------------------------
  154. %------------------------------------------------------------------------
  155. %%% @psdo control structure -- similar to Latex @for.
  156. %%% I redefined these with different names so that psfig can
  157. %%% be used with TeX as well as LaTeX, and so that it will not 
  158. %%% be vunerable to future changes in LaTeX's internal
  159. %%% control structure,
  160. %
  161. \def\@nnil{\@nil}
  162. \def\@empty{}
  163. \def\@psdonoop#1\@@#2#3{}
  164. \def\@psdo#1:=#2\do#3{\edef\@psdotmp{#2}\ifx\@psdotmp\@empty \else
  165.     \expandafter\@psdoloop#2,\@nil,\@nil\@@#1{#3}\fi}
  166. \def\@psdoloop#1,#2,#3\@@#4#5{\def#4{#1}\ifx #4\@nnil \else
  167.        #5\def#4{#2}\ifx #4\@nnil \else#5\@ipsdoloop #3\@@#4{#5}\fi\fi}
  168. \def\@ipsdoloop#1,#2\@@#3#4{\def#3{#1}\ifx #3\@nnil 
  169.        \let\@nextwhile=\@psdonoop \else
  170.       #4\relax\let\@nextwhile=\@ipsdoloop\fi\@nextwhile#2\@@#3{#4}}
  171. \def\@tpsdo#1:=#2\do#3{\xdef\@psdotmp{#2}\ifx\@psdotmp\@empty \else
  172.     \@tpsdoloop#2\@nil\@nil\@@#1{#3}\fi}
  173. \def\@tpsdoloop#1#2\@@#3#4{\def#3{#1}\ifx #3\@nnil 
  174.        \let\@nextwhile=\@psdonoop \else
  175.       #4\relax\let\@nextwhile=\@tpsdoloop\fi\@nextwhile#2\@@#3{#4}}
  176. %%% 
  177. %
  178. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  179. %%% file reading stuff from epsf.tex
  180. %%%   EPSF.TEX macro file:
  181. %%%   Written by Tomas Rokicki of Radical Eye Software, 29 Mar 1989.
  182. %%%   Revised by Don Knuth, 3 Jan 1990.
  183. %%%   Revised by Tomas Rokicki to accept bounding boxes with no
  184. %%%      space after the colon, 18 Jul 1990.
  185. %%%   Portions modified/removed for use in PSFIG package by
  186. %%%      J. Daniel Smith, 9 October 1990.
  187. %%%   Just the bit which knows about (atend) as a BoundingBox
  188. %
  189. %%%    hacked back a bit by SPQR 12/91
  190. %
  191. \long\def\epsfaux#1#2:#3\\{\ifx#1\epsfpercent
  192.    \def\testit{#2}\ifx\testit\epsfbblit
  193.     \@atendfalse
  194.         \epsf@atend #3 . \\%
  195.     \if@atend    
  196.        \if@verbose
  197.         \typeout{epsfig: found `(atend)'; continuing search}
  198.        \fi
  199.         \else
  200.         \epsfgrab #3 . . . \\%
  201.             \global\no@bbfalse
  202.         \fi
  203.    \fi\fi}%
  204. %
  205. %%% Determine if the stuff following the %%BoundingBox is `(atend)'
  206. %%% J. Daniel Smith.  Copied from \epsf@grab above.
  207. %
  208. \def\epsf@atendlit{(atend)} 
  209. %
  210. \def\epsf@atend #1 #2 #3\\{%
  211.    \def\epsf@tmp{#1}\ifx\epsf@tmp\empty
  212.       \epsf@atend #2 #3 .\\\else
  213.    \ifx\epsf@tmp\epsf@atendlit\@atendtrue\fi\fi}
  214.  
  215.  
  216. %%% End of file reading stuff from epsf.tex
  217. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  218.  
  219. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  220. %%% trigonometry stuff from "trig.tex"
  221. \chardef\letter = 11
  222. \chardef\other = 12
  223.  
  224. \newif\ifdebug %%% turn me on to see TeX hard at work ...
  225. \newif\ifc@mpute %%% don't need to compute some values
  226. \newif\if@atend
  227. \c@mputetrue % but assume that we do
  228.  
  229. \let\then = \relax
  230. \def\r@dian{pt }
  231. \let\r@dians = \r@dian
  232. \let\dimensionless@nit = \r@dian
  233. \let\dimensionless@nits = \dimensionless@nit
  234. \def\internal@nit{sp }
  235. \let\internal@nits = \internal@nit
  236. \newif\ifstillc@nverging
  237. \def \Mess@ge #1{\ifdebug \then \message {#1} \fi}
  238.  
  239. { %%% Things that need abnormal catcodes %%%
  240.     \catcode `\@ = \letter
  241.     \gdef \nodimen {\expandafter \n@dimen \the \dimen}
  242.     \gdef \term #1 #2 #3%
  243.            {\edef \t@ {\the #1}%%% freeze parameter 1 (count, by value)
  244.         \edef \t@@ {\expandafter \n@dimen \the #2\r@dian}%
  245.                    %%% freeze parameter 2 (dimen, by value)
  246.         \t@rm {\t@} {\t@@} {#3}%
  247.            }
  248.     \gdef \t@rm #1 #2 #3%
  249.            {{%
  250.         \count 0 = 0
  251.         \dimen 0 = 1 \dimensionless@nit
  252.         \dimen 2 = #2\relax
  253.         \Mess@ge {Calculating term #1 of \nodimen 2}%
  254.         \loop
  255.         \ifnum    \count 0 < #1
  256.         \then    \advance \count 0 by 1
  257.             \Mess@ge {Iteration \the \count 0 \space}%
  258.             \Multiply \dimen 0 by {\dimen 2}%
  259.             \Mess@ge {After multiplication, term = \nodimen 0}%
  260.             \Divide \dimen 0 by {\count 0}%
  261.             \Mess@ge {After division, term = \nodimen 0}%
  262.         \repeat
  263.         \Mess@ge {Final value for term #1 of 
  264.                 \nodimen 2 \space is \nodimen 0}%
  265.         \xdef \Term {#3 = \nodimen 0 \r@dians}%
  266.         \aftergroup \Term
  267.            }}
  268.     \catcode `\p = \other
  269.     \catcode `\t = \other
  270.     \gdef \n@dimen #1pt{#1} %%% throw away the ``pt''
  271. }
  272.  
  273. \def \Divide #1by #2{\divide #1 by #2} %%% just a synonym
  274.  
  275. \def \Multiply #1by #2%%% allows division of a dimen by a dimen
  276.        {{%%% should really freeze parameter 2 (dimen, passed by value)
  277.     \count 0 = #1\relax
  278.     \count 2 = #2\relax
  279.     \count 4 = 65536
  280.     \Mess@ge {Before scaling, count 0 = \the \count 0 \space and
  281.             count 2 = \the \count 2}%
  282.     \ifnum    \count 0 > 32767 %%% do our best to avoid overflow
  283.     \then    \divide \count 0 by 4
  284.         \divide \count 4 by 4
  285.     \else    \ifnum    \count 0 < -32767
  286.         \then    \divide \count 0 by 4
  287.             \divide \count 4 by 4
  288.         \else
  289.         \fi
  290.     \fi
  291.     \ifnum    \count 2 > 32767 %%% while retaining reasonable accuracy
  292.     \then    \divide \count 2 by 4
  293.         \divide \count 4 by 4
  294.     \else    \ifnum    \count 2 < -32767
  295.         \then    \divide \count 2 by 4
  296.             \divide \count 4 by 4
  297.         \else
  298.         \fi
  299.     \fi
  300.     \multiply \count 0 by \count 2
  301.     \divide \count 0 by \count 4
  302.     \xdef \product {#1 = \the \count 0 \internal@nits}%
  303.     \aftergroup \product
  304.        }}
  305.  
  306. \def\r@duce{\ifdim\dimen0 > 90\r@dian \then   % sin(x) = sin(180-x)
  307.         \multiply\dimen0 by -1
  308.         \advance\dimen0 by 180\r@dian
  309.         \r@duce
  310.         \else \ifdim\dimen0 < -90\r@dian \then  % sin(x) = sin(360+x)
  311.         \advance\dimen0 by 360\r@dian
  312.         \r@duce
  313.         \fi
  314.         \fi}
  315.  
  316. \def\Sine#1%
  317.        {{%
  318.     \dimen 0 = #1 \r@dian
  319.     \r@duce
  320.     \ifdim\dimen0 = -90\r@dian \then
  321.        \dimen4 = -1\r@dian
  322.        \c@mputefalse
  323.     \fi
  324.     \ifdim\dimen0 = 90\r@dian \then
  325.        \dimen4 = 1\r@dian
  326.        \c@mputefalse
  327.     \fi
  328.     \ifdim\dimen0 = 0\r@dian \then
  329.        \dimen4 = 0\r@dian
  330.        \c@mputefalse
  331.     \fi
  332. %
  333.     \ifc@mpute \then
  334.             % convert degrees to radians
  335.         \divide\dimen0 by 180
  336.         \dimen0=3.141592654\dimen0
  337. %
  338.         \dimen 2 = 3.1415926535897963\r@dian %%% a well-known constant
  339.         \divide\dimen 2 by 2 %%% we only deal with -pi/2 : pi/2
  340.         \Mess@ge {Sin: calculating Sin of \nodimen 0}%
  341.         \count 0 = 1 %%% see power-series expansion for sine
  342.         \dimen 2 = 1 \r@dian %%% ditto
  343.         \dimen 4 = 0 \r@dian %%% ditto
  344.         \loop
  345.             \ifnum    \dimen 2 = 0 %%% then we've done
  346.             \then    \stillc@nvergingfalse 
  347.             \else    \stillc@nvergingtrue
  348.             \fi
  349.             \ifstillc@nverging %%% then calculate next term
  350.             \then    \term {\count 0} {\dimen 0} {\dimen 2}%
  351.                 \advance \count 0 by 2
  352.                 \count 2 = \count 0
  353.                 \divide \count 2 by 2
  354.                 \ifodd    \count 2 %%% signs alternate
  355.                 \then    \advance \dimen 4 by \dimen 2
  356.                 \else    \advance \dimen 4 by -\dimen 2
  357.                 \fi
  358.         \repeat
  359.     \fi        
  360.             \xdef \sine {\nodimen 4}%
  361.             %\typeout {Sin: sine of #1 \space is \sine \space}%
  362.        }}
  363.  
  364. %%% Now the Cosine can be calculated easily by calling \Sine:
  365. %%%  cos(x) = sin(90-x)
  366. \def\Cosine#1{\ifx\sine\UnDefined\edef\Savesine{\relax}\else
  367.                      \edef\Savesine{\sine}\fi
  368.     {\dimen0=#1\r@dian\multiply\dimen0 by -1
  369.      \advance\dimen0 by 90\r@dian
  370.      \Sine{\nodimen 0}
  371.      \xdef\cosine{\sine}
  372.      %\typeout {Cosine: cos of \space \nodimen 0 \space is \cosine \space}%
  373.      \xdef\sine{\Savesine}}}          
  374. %%% end of trig stuff
  375. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  376. %
  377. \def\psdraft{\def\@psdraft{0}}
  378. \def\psfull{\def\@psdraft{100}}
  379. \psfull
  380. %
  381. \newif\if@draftbox
  382. \def\psnodraftbox{\@draftboxfalse}
  383. \@draftboxtrue
  384. %
  385. \newif\if@noisy
  386. \def\pssilent{\@noisyfalse}
  387. \def\psnoisy{\@noisytrue}
  388. \@noisyfalse
  389.  
  390. %%% These are for the option list.
  391. %%% A specification of the form a = b maps to calling \@p@@sa{b}
  392. \newif\if@bbllx
  393. \newif\if@bblly
  394. \newif\if@bburx
  395. \newif\if@bbury
  396. \newif\if@height
  397. \newif\if@width
  398. \newif\if@rheight
  399. \newif\if@rwidth
  400. \newif\if@angle
  401. \newif\if@clip
  402. \newif\if@verbose
  403. \newif\if@prologfile
  404. \def\@p@@sprolog#1{\@prologfiletrue\def\@prologfileval{#1}}
  405. \def\@p@@sclip#1{\@cliptrue}
  406. %
  407. %%% if this is true, the original Darrell macros and specials are used
  408. \newif\ifuse@psfig
  409. %
  410. \def\@p@@sfile#1{%
  411. \def\@p@sfile{NO FILE: #1}%
  412. \def\@p@sfilefinal{NO FILE: #1}%
  413.     \openin1=#1
  414.     \ifeof1\closein1
  415.         \openin1=#1.bb
  416.             \ifeof1\closein1
  417.                 \if@bbllx\if@bblly\if@bburx\if@bbury% added 6/91 Rob Russell
  418.                           \def\@p@sfile{#1}%
  419.                           \def\@p@sfilefinal{#1}%
  420.                     \fi\fi\fi
  421.                 \else
  422.                     \@latexerr{ERROR! PostScript file #1 not found}\@whattodo
  423.                     \@p@@sbbllx{100bp}
  424.                     \@p@@sbblly{100bp}
  425.                     \@p@@sbburx{200bp}
  426.                     \@p@@sbbury{200bp}
  427.                     \def\@p@scost{200}
  428.                 \fi
  429.             \else
  430.                 \closein1%
  431.                 \edef\@p@sfile{#1.bb}%
  432.                 \edef\@p@sfilefinal{"`zcat `texfind #1.Z`"}%
  433.             \fi
  434.     \else\closein1
  435.             \edef\@p@sfile{#1}%
  436.             \edef\@p@sfilefinal{#1}%
  437.     \fi%
  438. }
  439.  % alternative syntax: figure=
  440. \let\@p@@sfigure\@p@@sfile
  441. %
  442. \def\@p@@sbbllx#1{
  443.         %\typeout{bbllx is #1}
  444.         \use@psfigtrue
  445.         \@bbllxtrue
  446.         \dimen100=#1
  447.         \edef\@p@sbbllx{\number\dimen100}
  448. }
  449. \def\@p@@sbblly#1{
  450.         %\typeout{bblly is #1}
  451.         \use@psfigtrue
  452.         \@bbllytrue
  453.         \dimen100=#1
  454.         \edef\@p@sbblly{\number\dimen100}
  455. }
  456. \def\@p@@sbburx#1{
  457.         %\typeout{bburx is #1}
  458.         \use@psfigtrue
  459.         \@bburxtrue
  460.         \dimen100=#1
  461.         \edef\@p@sbburx{\number\dimen100}
  462. }
  463. \def\@p@@sbbury#1{
  464.         %\typeout{bbury is #1}
  465.         \use@psfigtrue
  466.         \@bburytrue
  467.         \dimen100=#1
  468.         \edef\@p@sbbury{\number\dimen100}
  469. }
  470. \def\@p@@sheight#1{
  471.         \@heighttrue
  472.         \epsfysize=#1
  473.         \dimen100=#1
  474.            \edef\@p@sheight{\number\dimen100}
  475.         %\typeout{Height is \@p@sheight}
  476. }
  477. \def\@p@@swidth#1{
  478.         %\typeout{Width is #1}
  479.         \@widthtrue
  480.         \epsfxsize=#1
  481.         \dimen100=#1
  482.         \edef\@p@swidth{\number\dimen100}
  483. }
  484. \def\@p@@srheight#1{
  485.         %\typeout{Reserved height is #1}
  486.         \@rheighttrue\use@psfigtrue
  487.         \dimen100=#1
  488.         \edef\@p@srheight{\number\dimen100}
  489. }
  490. \def\@p@@srwidth#1{
  491.         %\typeout{Reserved width is #1}
  492.         \@rwidthtrue\use@psfigtrue
  493.         \dimen100=#1
  494.         \edef\@p@srwidth{\number\dimen100}
  495. }
  496. \def\@p@@sangle#1{
  497.         %\typeout{Rotation is #1}
  498.         \use@psfigtrue
  499.         \@angletrue
  500. %        \dimen100=#1
  501.         \edef\@p@sangle{#1} %\number\dimen100}
  502. }
  503. \def\@p@@ssilent#1{ 
  504.         \@verbosefalse
  505. }
  506. \def\@cs@name#1{\csname #1\endcsname}
  507. \def\@setparms#1=#2,{\@cs@name{@p@@s#1}{#2}}
  508. %
  509. %%% initialize the defaults (size the size of the figure)
  510. %
  511. \def\ps@init@parms{
  512.         \@bbllxfalse \@bbllyfalse
  513.         \@bburxfalse \@bburyfalse
  514.         \@heightfalse \@widthfalse
  515.         \@rheightfalse \@rwidthfalse
  516.         \def\@p@sbbllx{}\def\@p@sbblly{}
  517.         \def\@p@sbburx{}\def\@p@sbbury{}
  518.         \def\@p@sheight{}\def\@p@swidth{}
  519.         \def\@p@srheight{}\def\@p@srwidth{}
  520.         \def\@p@sangle{0}
  521.         \def\@p@sfile{}
  522.         \def\@p@scost{10}
  523.         \use@psfigfalse
  524.         \@prologfilefalse
  525.         \def\@sc{}
  526.         \if@noisy
  527.             \@verbosetrue
  528.         \else
  529.             \@verbosefalse
  530.         \fi
  531.         \@clipfalse
  532. }
  533. %
  534. %%% Go through the options setting things up.
  535. %
  536. \def\parse@ps@parms#1{
  537.          \@psdo\@psfiga:=#1\do
  538.            {\expandafter\@setparms\@psfiga,}
  539. \if@prologfile 
  540. \special{header=\@prologfileval}
  541. \fi
  542. }
  543. %
  544. %%% Compute bb height and width
  545. %
  546. \newif\ifno@bb
  547. \def\bb@missing{
  548.     \epsfgetbb{\@p@sfile}
  549.         \ifepsfbbfound\no@bbfalse\else\no@bbtrue\bb@cull\epsfllx\epsflly\epsfurx\epsfury\fi
  550. }    
  551. \def\bb@cull#1#2#3#4{
  552.     \dimen100=#1 bp\edef\@p@sbbllx{\number\dimen100}
  553.     \dimen100=#2 bp\edef\@p@sbblly{\number\dimen100}
  554.     \dimen100=#3 bp\edef\@p@sbburx{\number\dimen100}
  555.     \dimen100=#4 bp\edef\@p@sbbury{\number\dimen100}
  556.     \no@bbfalse
  557. }
  558.  
  559. \newdimen\p@intvaluex
  560. \newdimen\p@intvaluey
  561. \newdimen\@ffsetvalue
  562. \newdimen\x@ffsetvalue
  563. \newdimen\y@ffsetvalue
  564.  
  565. %%% Calculate \@ffsetvalue = (#2 - #1) \sin\theta
  566. %%%  The sine of the angle is already stored in \sine.
  567. %%%  If (#2-#1)>0, then the result is zero in the 2nd and 4th quadrants, and
  568. %%%  if (#2-#1)<0, then the result is zero in the 1st and 3rd quadrants.
  569. %%%  Only the x coordinate needs an offset in the 1st and 3rd quadrants,
  570. %%%  and only the y coordinate needs an offset otherwise.
  571.  
  572. \def\compute@offset#1#2{{\dimen0=#1 sp\dimen1=#2 sp
  573.             \advance\dimen1 by -\dimen0
  574.             \dimen1=\sine\dimen1
  575.             \dimen0=\cosine\dimen1
  576.             \ifdim\dimen0<0sp \dimen1=0sp \fi
  577.             \global\@ffsetvalue=\dimen1}}
  578.  
  579. %%% rotate point (#1,#2) about (0,0).
  580. %%% The sine and cosine of the angle are already stored in \sine and
  581. %%% \cosine.  The result is placed in (\p@intvaluex, \p@intvaluey).
  582. \def\rotate@#1#2{{\dimen0=#1 sp\dimen1=#2 sp
  583. %%%                calculate x' = x \cos\theta - y \sin\theta
  584.           \global\p@intvaluex=\cosine\dimen0
  585.           \dimen3=\sine\dimen1
  586.           \global\advance\p@intvaluex by -\dimen3
  587. %%%         calculate y' = x \sin\theta + y \cos\theta
  588.           \global\p@intvaluey=\sine\dimen0
  589.           \dimen3=\cosine\dimen1
  590.           \global\advance\p@intvaluey by \dimen3
  591.           }}
  592. %%% rotate point (#1,#2) about the point (#3,#4), finding the x value.
  593. %%% The sine and cosine of the angle are already stored in \sine and
  594. %%% \cosine.  The result is placed in \p@intvaluex
  595. %\def\rotate@x#1#2#3#4{{\dimen0=#1 sp
  596. %            \dimen1=#2 sp
  597. %            \dimen2=#3 sp
  598. %            \dimen4=#4 sp
  599. %            \advance\dimen0 by -\dimen3
  600. %            \dimen0=\cosine\dimen0
  601. %            \advance\dimen4 by -\dimen2
  602. %            \dimen4=\sine\dimen4
  603. %               \global\p@intvaluex=\dimen0
  604. %               \global\advance\p@intvaluex by \dimen4
  605. %            \global\advance\p@intvaluex by \dimen3
  606. %
  607. %}}
  608. \def\compute@bb{
  609.         \no@bbfalse
  610.         \if@bbllx \else \no@bbtrue \fi
  611.         \if@bblly \else \no@bbtrue \fi
  612.         \if@bburx \else \no@bbtrue \fi
  613.         \if@bbury \else \no@bbtrue \fi
  614.         \ifno@bb \bb@missing \fi
  615.         \ifno@bb
  616.             \@latexerr{ERROR! cannot locate BB!}\@whattodobb
  617.             \@p@@sbbllx{100bp}
  618.             \@p@@sbblly{100bp}
  619.             \@p@@sbburx{200bp}
  620.             \@p@@sbbury{200bp}
  621.             \def\@p@scost{200}
  622.         \fi
  623.         %\typeout{BB: \@p@sbbllx, \@p@sbblly, \@p@sbburx, \@p@sbbury} 
  624.         \if@angle 
  625.             \Sine{\@p@sangle}\Cosine{\@p@sangle}
  626.             \compute@offset{\@p@sbblly}{\@p@sbbury}
  627.             \x@ffsetvalue=\@ffsetvalue
  628.             % Note that arguments are reversed to
  629.             %  give a negative interval:
  630.             \compute@offset{\@p@sbburx}{\@p@sbbllx}
  631.             \y@ffsetvalue=\@ffsetvalue
  632.  
  633.             \rotate@{\@p@sbbllx}{\@p@sbblly}
  634.             \advance\p@intvaluex by -\x@ffsetvalue
  635.             \advance\p@intvaluey by -\y@ffsetvalue
  636.             \edef\@p@sbbllx{\number\p@intvaluex}
  637.             \edef\@p@sbblly{\number\p@intvaluey}
  638.  
  639.             \rotate@{\@p@sbburx}{\@p@sbbury}
  640.             \advance\p@intvaluex by \x@ffsetvalue
  641.             \advance\p@intvaluey by \y@ffsetvalue
  642.             \edef\@p@sbburx{\number\p@intvaluex}
  643.             \edef\@p@sbbury{\number\p@intvaluey}
  644. %        swap LL and UR if necessary
  645. %\typeout{rotated BB: \@p@sbbllx, \@p@sbblly, \@p@sbburx, \@p@sbbury}
  646.             {
  647.              \count0=\@p@sbbllx \count1=\@p@sbblly
  648.               \count2=\@p@sbburx \count3=\@p@sbbury
  649.              \dimen0=\@p@sbbllx sp\dimen1=\@p@sbblly sp
  650.               \dimen2=\@p@sbburx sp\dimen3=\@p@sbbury sp
  651.              \dimen203=\dimen2 \advance\dimen203 by -\dimen0
  652.              \dimen204=\dimen3 \advance\dimen204 by -\dimen1
  653.              \ifdim\dimen203<0sp 
  654.                   \count203=\count2 \count2=\count0 
  655.                   \count0=\count203 
  656.                   \global\edef\@p@sbbllx{\number\count0}
  657.                   \global\edef\@p@sbburx{\number\count2}
  658.              \fi
  659.              \ifdim\dimen204<0sp 
  660.                    \count204=\count3
  661.                    \count3=\count1
  662.                    \count1=\count204
  663.                    \global\edef\@p@sbblly{\number\count1}
  664.                    \global\edef\@p@sbbury{\number\count3}
  665.              \fi
  666.             }
  667. %\typeout{after swap BB: \@p@sbbllx, \@p@sbblly, \@p@sbburx, \@p@sbbury}
  668.         \fi
  669.         \count203=\@p@sbburx
  670.         \count204=\@p@sbbury
  671.         \advance\count203 by -\@p@sbbllx
  672.         \advance\count204 by -\@p@sbblly
  673.         \edef\@bbw{\number\count203}
  674.         \edef\@bbh{\number\count204}
  675.         %\typeout{ bbh = \@bbh, bbw = \@bbw }
  676. }
  677. %
  678. %%% \in@hundreds performs #1 * (#2 / #3) correct to the hundreds,
  679. %    then leaves the result in @result
  680. %
  681. \def\in@hundreds#1#2#3{\count240=#2 \count241=#3
  682.              \count100=\count240    % 100 is first digit #2/#3
  683.              \divide\count100 by \count241
  684.              \count101=\count100
  685.              \multiply\count101 by \count241
  686.              \advance\count240 by -\count101
  687.              \multiply\count240 by 10
  688.              \count101=\count240    %101 is second digit of #2/#3
  689.              \divide\count101 by \count241
  690.              \count102=\count101
  691.              \multiply\count102 by \count241
  692.              \advance\count240 by -\count102
  693.              \multiply\count240 by 10
  694.              \count102=\count240    % 102 is the third digit
  695.              \divide\count102 by \count241
  696.              \count200=#1\count205=0
  697.              \count201=\count200
  698.             \multiply\count201 by \count100
  699.              \advance\count205 by \count201
  700.              \count201=\count200
  701.             \divide\count201 by 10
  702.             \multiply\count201 by \count101
  703.             \advance\count205 by \count201
  704.             %
  705.              \count201=\count200
  706.             \divide\count201 by 100
  707.             \multiply\count201 by \count102
  708.             \advance\count205 by \count201
  709.             %
  710.              \edef\@result{\number\count205}
  711. }
  712. \def\compute@wfromh{
  713.         % computing : width = height * (bbw / bbh)
  714.         \in@hundreds{\@p@sheight}{\@bbw}{\@bbh}
  715.         %\typeout{ \@p@sheight * \@bbw / \@bbh, = \@result }
  716.         \edef\@p@swidth{\@result}
  717.         %\typeout{w from h: width is \@p@swidth}
  718. }
  719. \def\compute@hfromw{
  720.         % computing : height = width * (bbh / bbw)
  721.         \in@hundreds{\@p@swidth}{\@bbh}{\@bbw}
  722.         %\typeout{ \@p@swidth * \@bbh / \@bbw = \@result }
  723.         \edef\@p@sheight{\@result}
  724.         %\typeout{h from w : height is \@p@sheight}
  725. }
  726. \def\compute@handw{
  727.         \if@height 
  728.             \if@width
  729.             \else
  730.                 \compute@wfromh
  731.             \fi
  732.         \else 
  733.             \if@width
  734.                 \compute@hfromw
  735.             \else
  736.                 \edef\@p@sheight{\@bbh}
  737.                 \edef\@p@swidth{\@bbw}
  738.             \fi
  739.         \fi
  740. }
  741. \def\compute@resv{
  742.         \if@rheight \else \edef\@p@srheight{\@p@sheight} \fi
  743.         \if@rwidth \else \edef\@p@srwidth{\@p@swidth} \fi
  744.         %\typeout{rheight = \@p@srheight, rwidth = \@p@srwidth}
  745. }
  746. %        
  747. %%% Compute any missing values
  748. \def\compute@sizes{
  749.     \compute@bb
  750.     \compute@handw
  751.     \compute@resv
  752. }
  753. %
  754. %%% \epsfig
  755. %%% usage : \epsfig{file=, height=, width=, bbllx=, bblly=, bburx=, bbury=,
  756. %            rheight=, rwidth=, angle=, clip=}
  757. %
  758. %%% "clip=" is a switch and takes no value, but the `=' must be present.
  759. %------------------------------------------------------------------
  760. %%% by the way, possible parameters to the PSfile= command in dvips are:
  761. %%%                    llx
  762. %%%                    lly
  763. %%%                    urx
  764. %%%                    ury
  765. %%%                    rwi
  766. %    hoffset    The horizontal offset (default 0)
  767. %    voffset    The vertical offset (default 0)
  768. %    hsize    The horizontal clipping size (default 612)
  769. %    vsize    The vertical clipping size (default 792)
  770. %    hscale    The horizontal scaling factor (default 100)
  771. %    vscale    The vertical scaling factor (default 100)
  772. %    angle    The rotation (default 0)
  773. %------------------------------------------------------------------
  774. \def\psfig#1{\vbox {
  775.     % do a zero width hard space so that a single
  776.     % \epsfig in a centering enviornment will behave nicely
  777.     %{\setbox0=\hbox{\ }\ \hskip-\wd0}
  778.     %
  779.     \ps@init@parms
  780.     \parse@ps@parms{#1}
  781.     %
  782.     \ifnum\@p@scost<\@psdraft
  783.         \typeout{[\@p@sfilefinal]}
  784.         \if@verbose
  785.             \typeout{epsfig: using PSFIG macros}
  786.         \fi
  787.         \psfig@method
  788.     \else
  789.         \epsfig@draft
  790.     \fi
  791. }}
  792.  
  793. \def\epsfig#1{\vbox {
  794.     % do a zero width hard space so that a single
  795.     % \epsfig in a centering enviornment will behave nicely
  796.     %{\setbox0=\hbox{\ }\ \hskip-\wd0}
  797.     %
  798.     \ps@init@parms
  799.     \parse@ps@parms{#1}
  800.     %
  801.     \ifnum\@p@scost<\@psdraft
  802.         \typeout{[\@p@sfilefinal]}
  803.         \if@clip\use@psfigtrue\fi
  804.         \if@angle\use@psfigtrue\fi
  805.         \ifuse@psfig
  806.             \if@verbose
  807.                 \typeout{epsfig: using PSFIG macros}
  808.             \fi
  809.             \psfig@method
  810.         \else
  811.             \if@verbose
  812.                 \typeout{epsfig: using EPSF macros}
  813.             \fi
  814.             \epsf@method
  815.         \fi
  816.     \else
  817.         \epsfig@draft
  818.     \fi
  819. }}
  820.  
  821.  
  822. \def\epsf@method{%
  823.     \epsfgetbb{\@p@sfile}%
  824.     \epsfsetgraph{\@p@sfilefinal}
  825. }
  826. \def\psfig@method{%
  827.     \compute@sizes
  828.     \special{ps::[begin]  \@p@swidth \space \@p@sheight \space%
  829.     \@p@sbbllx \space \@p@sbblly \space%
  830.     \@p@sbburx \space \@p@sbbury \space%
  831.     startTexFig \space }%
  832.     \if@angle
  833.         \special {ps:: \@p@sangle \space rotate \space} 
  834.     \fi
  835.     \if@clip
  836.         \if@verbose
  837.             \typeout{(clipped to BB) }
  838.         \fi
  839.         \special{ps:: doclip \space }%
  840.     \fi
  841.     \special{ps: plotfile \@p@sfilefinal \space }%
  842.     \special{ps::[end] endTexFig \space }%
  843.     % Create the vbox to reserve the space for the figure%
  844.     \vbox to \@p@srheight true sp{\hbox to \@p@srwidth true sp{\hss}\vss}
  845. }
  846. %
  847. % draft figure, just reserve the space and print the
  848. % path name.
  849. \def\epsfig@draft{
  850. \compute@sizes
  851. \if@draftbox
  852.     % Verbose draft: print file name in box
  853.     % NOTE: fbox is a LaTeX command!
  854.     \hbox{\fbox{\vbox to \@p@srheight true sp{
  855.     \vss\hbox to \@p@srwidth true sp{ \hss \@p@sfilefinal \hss }\vss
  856.     }}}
  857. \else
  858.     % Non-verbose draft
  859.     \vbox to \@p@srheight true sp{%
  860.     \vss\hbox to \@p@srwidth true sp{\hss}\vss}
  861. \fi    
  862. }
  863. \epsfigRestoreAt
  864.  
  865.  
  866.